<?php

namespace App\Admin\Controllers;

use App\Models\Course;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class LiveController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '直播管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Course());
        //直播筛选
         $grid->model()->where('type',Course::TYPE_LIVE);
        //搜索
        $grid->filter(function($filter){
            // 去掉默认的id过滤器
            $filter->disableIdFilter();
            // 在这里添加字段过滤器
            $filter->like('name', '直播名称');
        });   

        $grid->column('id', __('Id'));
        $grid->column('name', __('直播/录播名称'));
        $grid->column('thumb', __('直播图片'));
        $grid->column('is_recommend', __('是否推荐'));
        $grid->column('start_time', __('开始时间'));
        $grid->column('end_time', __('结束时间'));
        $grid->column('live_status', __('直播状态'));
        $grid->column('status', __('状态'));


        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Course::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('thumb', __('Thumb'));
        $show->field('status', __('Status'));
        $show->field('description', __('Description'));
        $show->field('content', __('Content'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('sort', __('Sort'));
        $show->field('is_recommend', __('Is recommend'));
        $show->field('type', __('Type'));
        $show->field('start_time', __('Start time'));
        $show->field('end_time', __('End time'));
        $show->field('live_status', __('Live status'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Course());
        $form->hidden('type', Course::TYPE_LIVE);
        $form->text('name', __('直播名称'));
        $form->image('thumb', __('直播图片'));
        $form->textarea('description', __('直播描述'));
        $form->textarea('content', __('直播内容'));
        $form->number('sort', __('排序'))->default(0);
        $form->switch('is_recommend', __('是否推荐'))->default(0); 
        $form->datetime('start_time', __('直播开始时间'))->default(date('Y-m-d H:i:s'));
        $form->datetime('end_time', __('直播结束时间'))->default(date('Y-m-d H:i:s'));
        $form->switch('status', __('状态'))->default(1);
        return $form;
    }
}
